<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fetch 发送 AJAX请求</title>
</head>

<body>
    <button>AJAX请求 Promise 封装</button>
    <script>
        const BASE_URL = "http://localhost:8000"
        const btn = document.querySelector('button');
        btn.onclick = function () {
            fetch(BASE_URL + "/fetch-server", {
                // method
                method: "POST",
                // header
                headers: {
                    name: "collins"
                },
                // body
                body: 'username=admin&password=admin'
            }).then(response => {
                // return response.text();
                // parse body as json data type
                return response.json();
            }).then(response => {
                console.log(response);
            })
        };
    </script>
</body>

</html>